import { Input, InputNumber, Select } from '@/components/AntdProxy';
import CardPanel from '@/components/CardPanel';
import CommonDrawer from '@/components/CommonDrawer';
import { CrudFormLayout } from '@/components/Crud';
import {
  DriverSelect,
  LineSelect,
  VehicleSelect,
} from '@/components/CustomForm';
import ImageUpload from '@/components/ImageUpload';
import ImageViewer from '@/components/ImageViewer';
import { CHECK_TYPE_OPTIONS } from '@/constants/enums';
import { REQUIRED } from '@/constants/rules';
import useMaterial from '@/hooks/useMaterial';
import request from '@/utils/request';
import { Button, Col, Form, message, Row } from 'antd';
import dayjs from 'dayjs';
import { useEffect, useMemo, useRef } from 'react';
import TextForm from '../TextForm';
import BindTrip from './BindTrip';
import styles from './index.less';

// 更改线路时需要连带出来的字段，其中“单价”字段两边没统一，所以特殊处理
const LINE_BIND_FIELDS = [
  'type',
  'linePrice',
  'driverPrice',
  'loadPrice',
  'unloadPrice',
  'infoPrice',
  'tarpaulinPrice',
  'passWeightPrice',
  'upCarPrice',
  'downCarPrice',
  'discrepancyPrice',
  'lossRatio',
  'checkType',
  'checkRatio',
];
const DATE_TIME_RULE =
  /^(?!0000)([0-9]{4})(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])([01][0-9]|2[0-3])([0-5][0-9])$/;
const Save = (props) => {
  const {
    source = 'default',
    open,
    record,
    onCancel,
    onOk,
    delBtnProps,
    preBtnProps,
    nextBtnProps,
    saveGoOnBtnProps,
    numberStep,
  } = props;
  const [form] = Form.useForm();
  const formCacheRef = useRef(null);
  const { materialTypeOptions } = useMaterial();
  useEffect(() => {
    if (open && record) {
      const relatedValue = {};
      LINE_BIND_FIELDS.forEach((field) => {
        relatedValue[field] = record?.[field] || formCacheRef.current?.[field];
      });
      let result = {
        ...record,
        lineId: record.lineId || formCacheRef.current?.lineId,
        vehicleId: record.vehicleId || formCacheRef.current?.vehicleId,
        loadDriverId: record.loadDriverId || formCacheRef.current?.loadDriverId,
        unloadDriverId:
          record.unloadDriverId || formCacheRef.current?.unloadDriverId,
        loadTime:
          record.loadTime || formCacheRef.current?.loadTime
            ? dayjs(record.loadTime || formCacheRef.current?.loadTime)?.format(
                'YYYYMMDDHHmm',
              )
            : undefined,
        unloadTime:
          record.unloadTime || formCacheRef.current?.unloadTime
            ? dayjs(
                record.unloadTime || formCacheRef.current?.unloadTime,
              )?.format('YYYYMMDDHHmm')
            : dayjs().format('YYYYMM'),
        loadWeightCodeImage: record.loadWeightCodeImage
          ? [{ url: record.loadWeightCodeImage }]
          : [],
        unloadWeightCodeImage: record.unloadWeightCodeImage
          ? [{ url: record.unloadWeightCodeImage }]
          : [],
        _loadEmptyWeight: record.loadEmptyWeight * record.checkRatio,
        _loadTotalWeight: record.loadTotalWeight * record.checkRatio,
        _loadWeight: record.loadWeight * record.checkRatio,
        _unloadEmptyWeight: record.unloadEmptyWeight * record.checkRatio,
        _unloadTotalWeight: record.unloadTotalWeight * record.checkRatio,
        _unloadWeight: record.unloadWeight * record.checkRatio,
      };
      if (!record?.lineId) {
        result = {
          ...result,
          ...relatedValue,
        };
      }
      // 计算totalPrice
      result.totalPrice = calculateTotalPrice(result);
      form.setFieldsValue(result);
    }
  }, [open, record]);

  const calculateTotalPrice = (values) => {
    const totalPrice =
      (values.loadPrice || 0) +
      (values.unloadPrice || 0) +
      (values.roadPrice || 0) +
      (values.etcPrice || 0) +
      (values.driverPrice || 0) +
      (values.tyrePrice || 0) +
      (values.infoPrice || 0) +
      (values.tarpaulinPrice || 0) +
      (values.passWeightPrice || 0) +
      (values.upCarPrice || 0) +
      (values.downCarPrice || 0) +
      (values.chargePrice || 0) +
      (values.trafficTicket || 0) +
      (values.repairPrice || 0) +
      (values.otherPrice || 0);
    return totalPrice;
  };

  const loadWeightCodeImage = Form.useWatch('loadWeightCodeImage', form);
  const unloadWeightCodeImage = Form.useWatch('unloadWeightCodeImage', form);

  const lineId = Form.useWatch('lineId', form);
  const vehicleId = Form.useWatch('vehicleId', form);
  const loadTime = Form.useWatch('loadTime', form);
  const unloadTime = Form.useWatch('unloadTime', form);

  // 总支出=装车费+卸车费+路桥费用+ETC费用+司机薪金+轮胎损耗+信息费+篷布费+过磅费+上车台费+下车台费+充电费+交警罚款+维修费。
  const loadPrice = Form.useWatch('loadPrice', form) || 0;
  const unloadPrice = Form.useWatch('unloadPrice', form) || 0;
  const roadPrice = Form.useWatch('roadPrice', form) || 0;
  const etcPrice = Form.useWatch('etcPrice', form) || 0;
  const driverPrice = Form.useWatch('driverPrice', form) || 0;
  const tyrePrice = Form.useWatch('tyrePrice', form) || 0;
  const infoPrice = Form.useWatch('infoPrice', form) || 0;
  const tarpaulinPrice = Form.useWatch('tarpaulinPrice', form) || 0;
  const passWeightPrice = Form.useWatch('passWeightPrice', form) || 0;
  const upCarPrice = Form.useWatch('upCarPrice', form) || 0;
  const downCarPrice = Form.useWatch('downCarPrice', form) || 0;
  const chargePrice = Form.useWatch('chargePrice', form) || 0;
  const trafficTicket = Form.useWatch('trafficTicket', form) || 0;
  const repairPrice = Form.useWatch('repairPrice', form) || 0;
  const otherPrice = Form.useWatch('otherPrice', form) || 0;
  const linePrice = Form.useWatch('linePrice', form) || 0;
  const unloadWeight = Form.useWatch('unloadWeight', form) || 0;
  const taskPrice = Form.useWatch('taskPrice', form) || 0;
  const totalPrice = Form.useWatch('totalPrice', form) || 0;
  const settlement = Form.useWatch('settlement', form) || 0;
  const grossProfit = Form.useWatch('grossProfit', form) || 0;
  const loadWeight = Form.useWatch('loadWeight', form) || 0;
  const lossRatio = Form.useWatch('lossRatio', form) || 0;
  const discrepancyWeight = Form.useWatch('discrepancyWeight', form) || 0;
  const standardLossWeight = Form.useWatch('standardLossWeight', form) || 0;
  const lossPrice = Form.useWatch('lossPrice', form) || 0;
  const discrepancyPrice = Form.useWatch('discrepancyPrice', form) || 0;
  const lossWeight = Form.useWatch('lossWeight', form) || 0;
  const checkType = Form.useWatch('checkType', form) || 0;
  const checkRatio = Form.useWatch('checkRatio', form) || 1;

  const _loadEmptyWeight = Form.useWatch('_loadEmptyWeight', form) || 0;
  const _loadTotalWeight = Form.useWatch('_loadTotalWeight', form) || 0;
  const _loadWeight = Form.useWatch('_loadWeight', form) || 0;
  const _unloadEmptyWeight = Form.useWatch('_unloadEmptyWeight', form) || 0;
  const _unloadTotalWeight = Form.useWatch('_unloadTotalWeight', form) || 0;
  const _unloadWeight = Form.useWatch('_unloadWeight', form) || 0;

  const unit = checkType === 0 ? '吨' : '方';
  useEffect(() => {
    form.setFieldsValue({
      loadEmptyWeight: _loadEmptyWeight / checkRatio,
      loadTotalWeight: _loadTotalWeight / checkRatio,
      loadWeight: _loadWeight / checkRatio,
    });
  }, [_loadEmptyWeight, _loadTotalWeight, _loadWeight, checkRatio]);
  useEffect(() => {
    form.setFieldsValue({
      unloadEmptyWeight: _unloadEmptyWeight / checkRatio,
      unloadTotalWeight: _unloadTotalWeight / checkRatio,
      unloadWeight: _unloadWeight / checkRatio,
    });
  }, [_unloadEmptyWeight, _unloadTotalWeight, _unloadWeight, checkRatio]);

  useEffect(() => {
    const totalPrice =
      loadPrice +
      unloadPrice +
      roadPrice +
      etcPrice +
      driverPrice +
      tyrePrice +
      infoPrice +
      tarpaulinPrice +
      passWeightPrice +
      upCarPrice +
      downCarPrice +
      chargePrice +
      trafficTicket +
      repairPrice +
      otherPrice;
    form.setFieldsValue({
      totalPrice,
    });
  }, [
    loadPrice,
    unloadPrice,
    roadPrice,
    etcPrice,
    driverPrice,
    tyrePrice,
    infoPrice,
    tarpaulinPrice,
    passWeightPrice,
    upCarPrice,
    downCarPrice,
    chargePrice,
    trafficTicket,
    repairPrice,
    otherPrice,
  ]);

  // 结算金额=任务营收-损耗金额
  useEffect(() => {
    form.setFieldsValue({
      settlement: taskPrice - lossPrice,
    });
  }, [taskPrice, lossPrice]);

  const onCtrlS = async () => {
    const goOn = saveGoOnBtnProps?.style?.display !== 'none';
    // 执行保存操作
    await handleOk('save', goOn);
  };

  // 检测操作系统类型
  const isMacOS = () => {
    return navigator.platform.toUpperCase().indexOf('MAC') >= 0;
  };

  // 键盘事件处理
  useEffect(() => {
    const handleKeyDown = (event) => {
      // 只在open为true且record有值时执行
      if (!open || !record) {
        return;
      }

      const isMac = isMacOS();
      const isCommandS = isMac && event.metaKey && event.key === 's';
      const isCtrlS = !isMac && event.ctrlKey && event.key === 's';

      if (isCommandS || isCtrlS) {
        event.preventDefault(); // 屏蔽浏览器默认的保存行为
        onCtrlS();
      }
    };

    // 添加事件监听器
    document.addEventListener('keydown', handleKeyDown);

    // 清理函数
    return () => {
      document.removeEventListener('keydown', handleKeyDown);
    };
  }, [open, record]); // 依赖open和record，当它们变化时重新绑定事件

  // 任务营收=线路运价*卸车净重
  useEffect(() => {
    form.setFieldsValue({
      taskPrice: linePrice * unloadWeight,
    });
  }, [linePrice, unloadWeight]);

  // 营收毛利=结算金额-总支出
  useEffect(() => {
    form.setFieldsValue({
      grossProfit: settlement - totalPrice,
    });
  }, [settlement, totalPrice]);

  // 毛利率=营收毛利/结算金额*100%
  useEffect(() => {
    form.setFieldsValue({
      profitMargin:
        grossProfit && settlement ? (grossProfit / settlement) * 100 : 0,
    });
  }, [grossProfit, settlement]);

  // 结算重量：当装车净重或卸车净重都大于0时，取最小值；如果其中一个为0，则取非0，默认0
  useEffect(() => {
    let weights = 0;
    if (loadWeight > 0 && unloadWeight > 0) {
      weights = Math.min(loadWeight, unloadWeight);
    } else if (loadWeight > 0) {
      weights = loadWeight;
    } else if (unloadWeight > 0) {
      weights = unloadWeight;
    }
    form.setFieldsValue({
      weights,
    });
  }, [loadWeight, unloadWeight]);

  // 磅差：当装车净重或卸车净重都大于0时，装车净重 - 卸车净重。如果其中一个为0，则取0，默认0
  useEffect(() => {
    let discrepancyWeight = 0;
    if (loadWeight > 0 && unloadWeight > 0) {
      discrepancyWeight = loadWeight - unloadWeight;
    }
    form.setFieldsValue({
      discrepancyWeight,
    });
  }, [loadWeight, unloadWeight]);

  // 合理损耗：装车净重*磅差系数，默认0
  useEffect(() => {
    form.setFieldsValue({
      standardLossWeight: loadWeight * lossRatio,
    });
  }, [loadWeight, lossRatio]);

  // 扣损重量：如果磅差大于合理损耗，则取差值，否则为0，默认0
  useEffect(() => {
    form.setFieldsValue({
      lossWeight:
        discrepancyWeight > standardLossWeight
          ? discrepancyWeight - standardLossWeight
          : 0,
    });
  }, [discrepancyWeight, standardLossWeight]);

  // 扣损金额：扣损重量*磅差单价，默认0
  useEffect(() => {
    form.setFieldsValue({
      lossPrice: lossWeight * discrepancyPrice,
    });
  }, [lossWeight, discrepancyPrice]);

  const images = useMemo(() => {
    const imgs = [];
    if (source === 'default') {
      record?.driverImage && imgs.push(record?.driverImage);
      loadWeightCodeImage?.forEach((item) => {
        item.url && imgs.push(item.url);
      });
      unloadWeightCodeImage?.forEach((item) => {
        item.url && imgs.push(item.url);
      });
    } else {
      record?.driverImage && imgs.push(record?.driverImage);
    }

    return imgs?.filter(Boolean);
  }, [loadWeightCodeImage, unloadWeightCodeImage, source, record]);

  const handleOk = async (type, goOn) => {
    try {
      const values = await form.validateFields();
      const url = record ? '/datas/weight/update' : '/datas/weight/add';
      const params = {
        ...values,
        loadTime: values.loadTime
          ? dayjs(values.loadTime)?.format('YYYY-MM-DD HH:mm:ss')
          : undefined,
        unloadTime: values.unloadTime
          ? dayjs(values.unloadTime)?.format('YYYY-MM-DD HH:mm:ss')
          : undefined,
        loadWeightCodeImage: loadWeightCodeImage?.[0]?.url,
        unloadWeightCodeImage: unloadWeightCodeImage?.[0]?.url,
      };
      delete params._loadEmptyWeight;
      delete params._loadTotalWeight;
      delete params._loadWeight;
      delete params._unloadEmptyWeight;
      delete params._unloadTotalWeight;
      delete params._unloadWeight;
      if (record) {
        params.weightId = record?.weightId;
      }

      await request({
        url,
        method: 'POST',
        data: params,
      });
      formCacheRef.current = { ...params };
      message.success(goOn ? '保存成功，即将跳转至下一条数据' : '保存成功');
      onOk(goOn);
    } catch (error) {
      console.error('保存失败:', error);
      message.error('保存失败');
    }
  };
  return (
    <CommonDrawer
      title={record ? `编辑(${numberStep})` : '新建'}
      open={open}
      onClose={onCancel}
      onOk={handleOk}
      afterOpenChange={(visible) => {
        if (!visible) {
          form.resetFields();
          formCacheRef.current = null;
        }
      }}
      width="100%"
      destroyOnHidden
      footer={
        <>
          <Button onClick={onCancel}>取消</Button>
          {record && (
            <Button {...delBtnProps} danger>
              删除
            </Button>
          )}
          {record && <Button {...preBtnProps}>上一条</Button>}
          {record && <Button {...nextBtnProps}>下一条</Button>}
          <Button type="primary" onClick={() => handleOk('save')}>
            保存修改
          </Button>
          {record && (
            <Button
              type="primary"
              onClick={() => handleOk('save', true)}
              {...saveGoOnBtnProps}
            >
              保存并继续
            </Button>
          )}
          {/* <Button type="primary" onClick={() => handleOk('confirm')}>
            确认收单
          </Button> */}
        </>
      }
    >
      <div className={styles.container}>
        <div className={styles.left}>
          <div className={styles.title}>
            <span>司机上传磅单</span>
          </div>
          <div className={styles.imgContainer}>
            <ImageViewer urls={images} />
          </div>
        </div>
        <div className={styles.right}>
          <div className={styles.title}>
            <span>基本信息</span>
            {record ? (
              <span style={{ marginLeft: 10, fontWeight: 'normal' }}>
                ({record.time})
              </span>
            ) : (
              ''
            )}
          </div>
          <Form form={form} layout="vertical">
            <CrudFormLayout itemMinWidth={180}>
              <Form.Item label="线路" name="lineId" rules={[REQUIRED]}>
                <LineSelect
                  onChange={(_val, _option) => {
                    const relatedValue = {};
                    LINE_BIND_FIELDS.forEach((field) => {
                      relatedValue[field] = _option?.[field];
                    });
                    form.setFieldsValue({
                      ...relatedValue,
                      linePrice: _option?.price,
                    });
                  }}
                />
              </Form.Item>
              <Form.Item label="车牌号" name="vehicleId" rules={[REQUIRED]}>
                <VehicleSelect
                  onChange={(_val, _option) => {
                    try {
                      const driverId = JSON.parse(_option?.drivers)?.[0]
                        ?.driverId;
                      if (driverId) {
                        form.setFieldsValue({
                          loadDriverId: driverId,
                          unloadDriverId: driverId,
                        });
                      } else {
                        form.resetFields(['loadDriverId', 'unloadDriverId']);
                      }
                    } catch (error) {
                      form.resetFields(['loadDriverId', 'unloadDriverId']);
                    }
                  }}
                />
              </Form.Item>
              <Form.Item label="装车司机" name="loadDriverId">
                <DriverSelect
                  onChange={(_val) => {
                    form.setFieldValue('unloadDriverId', _val);
                  }}
                />
              </Form.Item>
              <Form.Item
                label="卸车司机"
                name="unloadDriverId"
                rules={[REQUIRED]}
              >
                <DriverSelect />
              </Form.Item>
              <Form.Item label="物料类型" name="type" initialValue={7}>
                <Select
                  disabled
                  options={materialTypeOptions}
                  placeholder="请选择物料类型"
                />
              </Form.Item>
              <Form.Item label="客户名称" name="customerName">
                <Input placeholder="请输入客户名称" />
              </Form.Item>
              <Form.Item label="备注" name="remark">
                <Input placeholder="请输入备注" />
              </Form.Item>
              <Form.Item label="趟次" name="tripId">
                <BindTrip
                  lineId={lineId}
                  vehicleId={vehicleId}
                  loadTime={loadTime}
                  unloadTime={unloadTime}
                />
              </Form.Item>
              <Form.Item label="核算类型" name="checkType">
                <Select
                  options={CHECK_TYPE_OPTIONS}
                  placeholder="请选择核算类型"
                  disabled
                />
              </Form.Item>
              <Form.Item label="核算系数" name="checkRatio">
                <InputNumber placeholder="请输入核算系数" disabled />
              </Form.Item>
            </CrudFormLayout>
            <CardPanel
              title="磅单信息"
              right={
                source === 'default' && (
                  <aside className={styles.weightInfoImages}>
                    <div className={styles.weightInfoImagesItem}>
                      <Form.Item
                        label="装车榜单图片"
                        name="loadWeightCodeImage"
                      >
                        <ImageUpload maxCount={1} />
                      </Form.Item>
                    </div>
                    <div className={styles.weightInfoImagesItem}>
                      <Form.Item
                        label="卸车榜单图片"
                        name="unloadWeightCodeImage"
                      >
                        <ImageUpload maxCount={1} />
                      </Form.Item>
                    </div>
                  </aside>
                )
              }
            >
              <section className={styles.weightInfoContent}>
                <div className={styles.weightInfoContentItem}>
                  <Row className={styles.customRow} gutter={16}>
                    <Col span={12}>
                      <Form.Item label="装车磅单号" name="loadWeightCode">
                        <Input placeholder="请输入装车磅单号" />
                      </Form.Item>
                    </Col>
                    <Col span={12}>
                      <Form.Item
                        label="装车时间"
                        name="loadTime"
                        rules={[
                          // { required: true, message: '请输入装车时间' },
                          {
                            pattern: DATE_TIME_RULE,
                            message: '时间格式要求为:YYYYMMDDHHmm',
                          },
                        ]}
                        // initialValue={dayjs().format('YYYYMM')}
                      >
                        <Input placeholder="请输入装车时间" allowClear />
                      </Form.Item>
                    </Col>
                    <Col span={8}>
                      <Form.Item label="装车毛重" name="_loadEmptyWeight">
                        <InputNumber placeholder="请输入装车毛重" />
                      </Form.Item>
                    </Col>
                    <Col span={8}>
                      <Form.Item label="装车皮重" name="_loadTotalWeight">
                        <InputNumber placeholder="请输入装车皮重" />
                      </Form.Item>
                    </Col>
                    <Col span={8}>
                      <Form.Item label="装车净重" name="_loadWeight">
                        <InputNumber placeholder="请输入装车净重" />
                      </Form.Item>
                    </Col>
                    <Col span={8}>
                      <Form.Item
                        label={`装车毛重(${unit})`}
                        name="loadEmptyWeight"
                      >
                        <TextForm />
                      </Form.Item>
                    </Col>
                    <Col span={8}>
                      <Form.Item
                        label={`装车皮重(${unit})`}
                        name="loadTotalWeight"
                      >
                        <TextForm />
                      </Form.Item>
                    </Col>
                    <Col span={8}>
                      <Form.Item label={`装车净重(${unit})`} name="loadWeight">
                        <TextForm />
                      </Form.Item>
                    </Col>
                  </Row>
                </div>
                <div className={styles.weightInfoContentItem}>
                  <Row className={styles.customRow} gutter={16}>
                    <Col span={12}>
                      <Form.Item label="卸车磅单号" name="unloadWeightCode">
                        <Input placeholder="请输入卸车磅单号" />
                      </Form.Item>
                    </Col>
                    <Col span={12}>
                      <Form.Item
                        label="卸车时间"
                        name="unloadTime"
                        rules={[
                          { required: true, message: '请输入卸车时间' },
                          {
                            pattern: DATE_TIME_RULE,
                            message: '时间格式要求为:YYYYMMDDHHmm',
                          },
                        ]}
                        initialValue={dayjs().format('YYYYMM')}
                      >
                        <Input placeholder="请输入卸车时间" allowClear />
                      </Form.Item>
                    </Col>
                    <Col span={8}>
                      <Form.Item label="卸车毛重" name="_unloadEmptyWeight">
                        <InputNumber placeholder="请输入卸车毛重" />
                      </Form.Item>
                    </Col>
                    <Col span={8}>
                      <Form.Item label="卸车皮重" name="_unloadTotalWeight">
                        <InputNumber placeholder="请输入卸车皮重" />
                      </Form.Item>
                    </Col>
                    <Col span={8}>
                      <Form.Item label="卸车净重" name="_unloadWeight">
                        <InputNumber placeholder="请输入卸车净重" />
                      </Form.Item>
                    </Col>
                    <Col span={8}>
                      <Form.Item
                        label={`卸车毛重(${unit})`}
                        name="unloadEmptyWeight"
                      >
                        <TextForm />
                      </Form.Item>
                    </Col>
                    <Col span={8}>
                      <Form.Item
                        label={`卸车皮重(${unit})`}
                        name="unloadTotalWeight"
                      >
                        <TextForm />
                      </Form.Item>
                    </Col>
                    <Col span={8}>
                      <Form.Item
                        label={`卸车净重(${unit})`}
                        name="unloadWeight"
                      >
                        <TextForm />
                      </Form.Item>
                    </Col>
                  </Row>
                </div>
              </section>
            </CardPanel>
            <CardPanel title="费用信息" style={{ marginTop: 8 }}>
              <div style={{ padding: '0 24px' }}>
                <CrudFormLayout itemMinWidth={180}>
                  <Form.Item label="装车费用（元）" name="loadPrice">
                    <InputNumber placeholder="请输入装车费用" />
                  </Form.Item>
                  <Form.Item label="卸车费用（元）" name="unloadPrice">
                    <InputNumber placeholder="请输入卸车费用" />
                  </Form.Item>
                  <Form.Item label="路桥费用（元）" name="roadPrice">
                    <InputNumber placeholder="请输入路桥费用" />
                  </Form.Item>
                  <Form.Item label="ETC费用（元）" name="etcPrice">
                    <InputNumber placeholder="请输入ETC费用" />
                  </Form.Item>
                  <Form.Item label="司机薪金（元）" name="driverPrice">
                    <InputNumber placeholder="请输入司机薪金" />
                  </Form.Item>
                  <Form.Item label="轮胎损耗（元）" name="tyrePrice">
                    <InputNumber placeholder="请输入轮胎损耗" />
                  </Form.Item>
                  <Form.Item label="信息费（元）" name="infoPrice">
                    <InputNumber placeholder="请输入信息费" />
                  </Form.Item>
                  <Form.Item label="篷布费（元）" name="tarpaulinPrice">
                    <InputNumber placeholder="请输入篷布费" />
                  </Form.Item>
                  <Form.Item label="过磅费（元）" name="passWeightPrice">
                    <InputNumber placeholder="请输入过磅费" />
                  </Form.Item>
                  <Form.Item label="上车台费（元）" name="upCarPrice">
                    <InputNumber placeholder="请输入上车台费" />
                  </Form.Item>
                  <Form.Item label="下车台费（元）" name="downCarPrice">
                    <InputNumber placeholder="请输入下车台费" />
                  </Form.Item>
                  <Form.Item label="充电费（元）" name="chargePrice">
                    <InputNumber placeholder="请输入充电费" />
                  </Form.Item>
                  <Form.Item label="交警罚款（元）" name="trafficTicket">
                    <InputNumber placeholder="请输入交警罚款" />
                  </Form.Item>
                  <Form.Item label="维修费（元）" name="repairPrice">
                    <InputNumber placeholder="请输入维修费" />
                  </Form.Item>
                  <Form.Item label="其他费用（元）" name="otherPrice">
                    <InputNumber placeholder="请输入其他费用" />
                  </Form.Item>
                  <Form.Item label="总支出（元）" name="totalPrice">
                    <InputNumber disabled placeholder="请输入总支出" />
                  </Form.Item>
                </CrudFormLayout>
              </div>
            </CardPanel>
            <CardPanel title="磅差信息" style={{ marginTop: 8 }}>
              <div style={{ padding: '0 24px' }}>
                <CrudFormLayout itemMinWidth={180}>
                  {/* 结算重量（吨或方）、磅差（吨或方）、磅差单价（元/吨或方）、磅差系数、合理损耗（吨或方）、扣损重量（吨或方）、损耗金额（元） */}
                  <Form.Item label="结算重量（吨或方）" name="weights">
                    <InputNumber disabled placeholder="请输入结算重量" />
                  </Form.Item>
                  <Form.Item label="磅差（吨或方）" name="discrepancyWeight">
                    <InputNumber disabled placeholder="请输入磅差" />
                  </Form.Item>
                  <Form.Item
                    label="磅差单价（元/吨或方）"
                    name="discrepancyPrice"
                  >
                    <InputNumber placeholder="请输入磅差单价" />
                  </Form.Item>
                  <Form.Item label="磅差系数" name="lossRatio">
                    <InputNumber placeholder="请输入磅差系数" />
                  </Form.Item>
                  <Form.Item
                    label="合理损耗（吨或方）"
                    name="standardLossWeight"
                  >
                    <InputNumber disabled placeholder="请输入合理损耗" />
                  </Form.Item>
                  <Form.Item label="扣损重量（吨或方）" name="lossWeight">
                    <InputNumber disabled placeholder="请输入扣损重量" />
                  </Form.Item>
                  <Form.Item label="损耗金额（元）" name="lossPrice">
                    <InputNumber disabled placeholder="请输入损耗金额" />
                  </Form.Item>
                </CrudFormLayout>
              </div>
            </CardPanel>
            <CardPanel title="任务营收" style={{ marginTop: 8 }}>
              <div style={{ padding: '0 24px' }}>
                <CrudFormLayout itemMinWidth={180}>
                  <Form.Item label="线路运价（元/吨）" name="linePrice">
                    <InputNumber placeholder="请输入线路运价" />
                  </Form.Item>
                  <Form.Item label="任务营收（元）" name="taskPrice">
                    <InputNumber disabled placeholder="请输入任务营收" />
                  </Form.Item>
                  <Form.Item label="结算金额（元）" name="settlement">
                    <InputNumber disabled placeholder="请输入结算金额" />
                  </Form.Item>
                  <Form.Item label="营收毛利（元）" name="grossProfit">
                    <InputNumber disabled placeholder="请输入营收毛利" />
                  </Form.Item>
                  <Form.Item label="毛利率（%）" name="profitMargin">
                    <InputNumber disabled placeholder="请输入毛利率" />
                  </Form.Item>
                </CrudFormLayout>
              </div>
            </CardPanel>
          </Form>
        </div>
      </div>
    </CommonDrawer>
  );
};

export default Save;
